<template>
  <div class="content">
    <div class="grids">
      <div class="grid">
        <el-card class="box-card" shadow="never">
          <template #header>
            <div class="card-header">
              获取分享地址
            </div>
          </template>
          <el-button type="primary" :icon="CopyDocument" @click="copy">点击获取</el-button>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import { CopyDocument } from "@element-plus/icons-vue";
const { proxy } = getCurrentInstance();

onMounted(() => {});
let publishUrl = null;
let getInfo = async () => {
  let resp = await proxy.$apis.getDashboard();
  publishUrl = resp.publishUrl;
};

let copy = () => {
  let origin = window.location.origin;
  let href = `${origin}${publishUrl}`;
  navigator.clipboard
    .writeText(href)
    .then(() => {
      proxy.$utils.showToast("复制成功");
    })
    .catch((error) => {
      proxy.$utils.showToast("复制失败", 0);
    });
};
</script>

<style lang="scss" scoped>
.content {
  margin: 20px;
}
.grids {
  display: grid;
  grid-template-columns: repeat(4, minmax(0px, 1fr));
  gap: 8px 20px;
  grid-column-gap: 56rpx; //间隔
  .grid {
    grid-column: span 1 / span 1;
  }
}
</style>
